package 二叉树;

public class q404左叶子之和 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    class Solution {
        public int sumOfLeftLeaves(TreeNode root) {
            if (root == null) return 0;
            int leftValue = sumOfLeftLeaves(root.left);    // 左
            int rightValue = sumOfLeftLeaves(root.right);  // 右
            int midValue = 0;
            if (root.left != null && root.left.left == null && root.left.right == null) {
                midValue = root.left.val;
            }
            return leftValue + rightValue + midValue;
        }

    }
}
